package com.zdxk.msgPush.common.config;

import com.zdxk.msgPush.websocket.netty.server.NettyWebsocketServer;
import com.zdxk.msgPush.websocket.netty.service.NettyWebSocketChannelInitializer;
import com.zdxk.msgPush.websocket.netty.service.NettyWebSocketHandler;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;

@Configuration
@Component
public class NettySocketConfig {

    @Value("${websockt.netty.port}")
    private int websocketPort;


    @Bean
    public NettyWebSocketChannelInitializer nettyWebSocketChannelInitializer(){
        return new NettyWebSocketChannelInitializer(websocketPort);
    }

    @Bean
    public NettyWebsocketServer nettyWebsocketServer(NettyWebSocketChannelInitializer nettyWebSocketChannelInitializer){
        NettyWebsocketServer nettyWebsocketServer = new NettyWebsocketServer(websocketPort, nettyWebSocketChannelInitializer);
        new Thread(()->{
            nettyWebsocketServer.init();
        }).start();
        return nettyWebsocketServer;
    }


}
